
#ifndef ITEMTEST_H
#define ITEMTEST_H

#include "../../item/ItemUtil.h"

        int ItemUtil::Item::count_ = 0;
        int ItemUtil::LinkedItems::count_ = 0;
        int ItemUtil::LinkedItemsList::count_ = 0;
namespace test {
    TEST(TestItemUtil, TestLinkedItemsList) {
        vector< ItemUtil::Item*> vs;
        vs.push_back(new ItemUtil::Item{ 111,0.4,"tag2_12", "tag3_123" });
        vs.push_back(new ItemUtil::Item{ 111,0.8,"tag2_12", "tag3_123" });
        vs.push_back(new ItemUtil::Item{ 111,0.3,"tag2_12", "tag3_123" });
        vs.push_back(new ItemUtil::Item{ 111,0.9,"tag2_12", "tag3_123" });
        vs.push_back(new ItemUtil::Item{ 111,0.7,"tag2_12", "tag3_123" });
        

        ItemUtil::LinkedItemsList* ll = new ItemUtil::LinkedItemsList(vs[0], 5);
        ll->insert(vs[1]);
        ll->insert(vs[2]);
        ll->insert(vs[3]);
        ll->insert(vs[4]);

        EXPECT_EQ(5, ItemUtil::Item::count_);
        EXPECT_EQ(5, ItemUtil::LinkedItems::count_);
        EXPECT_EQ(5, ItemUtil::LinkedItemsList::count_);
        ItemUtil::LinkedItems* ptr = ll->head_;
        EXPECT_EQ(0.9, ptr->item_->score);
        ptr = ptr->next_;
        EXPECT_EQ(0.8, ptr->item_->score);
        ptr = ptr->next_;
        EXPECT_EQ(0.7, ptr->item_->score);
        ptr = ptr->next_;
        EXPECT_EQ(0.4, ptr->item_->score);
        ptr = ptr->next_;
        EXPECT_EQ(0.3, ptr->item_->score);
        vs.push_back(new ItemUtil::Item{ 111,0.6,"tag2_12", "tag3_123" });
        ll->insert(vs[5]);
        EXPECT_EQ(5, ItemUtil::Item::count_);
        EXPECT_EQ(5, ItemUtil::LinkedItems::count_);
        EXPECT_EQ(5, ItemUtil::LinkedItemsList::count_);
        //~
        delete ll;
        EXPECT_EQ(0, ItemUtil::Item::count_);
        EXPECT_EQ(0, ItemUtil::LinkedItems::count_);
        EXPECT_EQ(0, ItemUtil::LinkedItemsList::count_);


    }
    TEST(TestItemUtil, load_items) {
        map<string, ItemUtil::LinkedItemsList*>* ptr = ItemUtil::load_items();
        const int maxMPerTag = 10;
        for (auto iter = ptr->begin(); iter != ptr->end(); iter++) {
            EXPECT_LE(iter->second->count2_, maxMPerTag);
            delete iter->second;
        }
        EXPECT_EQ(0, ItemUtil::Item::count_);
        EXPECT_EQ(0, ItemUtil::LinkedItems::count_);
        EXPECT_EQ(0, ItemUtil::LinkedItemsList::count_);
        ptr->clear();
        delete ptr;
    }
}
#endif
